package com.lv.xulin.demopro;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.Toast;

import com.lv.adapter.EvAdapter;
import com.lv.adapter.RvAdapter;
import com.lv.entity.DingLink;
import com.lv.tools.view.XExpandableListView;
import com.lv.tools.view.XRecyclerView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by xulin on 2017/5/23.
 * xulin67@163.com
 */
// 仿钉钉联系人界面
public class DingLinkActivity extends Activity {


    private List<String> mDatas;
    private RvAdapter rvAdapter;

    private Map<String, List<String>> dataset = new HashMap<>();
//    private String[] parentList = new String[]{"first", "second", "third","第四个","第五个"};
    private List<DingLink> parentList=new ArrayList<>();
    private EvAdapter evAdapter;
    private List<String> childrenList1 = new ArrayList<>();
    private List<String> childrenList2 = new ArrayList<>();
    private List<String> childrenList3 = new ArrayList<>();

    @Bind(R.id.rvLinkman)
    XRecyclerView rvLinkman;
    @Bind(R.id.evLinkman)
    XExpandableListView evLinkman;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dinglink);
        ButterKnife.bind(this);

//        initRvListView();

        parentList.add(new DingLink(1,false,"钉钉好友"));
        parentList.add(new DingLink(2,false,"手机通讯录"));
        parentList.add(new DingLink(3,false,"我的群组"));
        parentList.add(new DingLink(4,false,"服务窗"));
        parentList.add(new DingLink(5,true,"企业开发群一号"));
        parentList.add(new DingLink(6,true,"企业开发群二号"));
        parentList.add(new DingLink(7,true,"常用联系人"));

        evListView();

    }

    private void initRvListView() {
        mDatas = new ArrayList<String>();
        for (int i = 10000; i <10005; i++)
        {
            mDatas.add("demo" + i);
        }
        rvAdapter = new RvAdapter(DingLinkActivity.this,mDatas);
        //设置布局管理器
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        rvLinkman.setLayoutManager(linearLayoutManager);
        rvLinkman.setAdapter(rvAdapter);
        rvAdapter.notifyDataSetChanged();
    }

    private void evListView() {
        initialData();
        evAdapter=new EvAdapter(DingLinkActivity.this,dataset,parentList);
        evLinkman.setAdapter(evAdapter);
        evLinkman.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
            @Override
            public boolean onChildClick(ExpandableListView expandableListView, View view,
                                        int parentPos, int childPos, long l) {
                Toast.makeText(DingLinkActivity.this, dataset.get(parentList.get(parentPos)).get(childPos), Toast.LENGTH_SHORT).show();
                return true;
            }
        });
    }

    private void initialData() {
        childrenList1.add(parentList.get(0).getFname()+ "-" + "first");
        childrenList1.add(parentList.get(0).getFname() + "-" + "second");
        childrenList1.add(parentList.get(0).getFname() + "-" + "third");
        childrenList2.add(parentList.get(1).getFname() + "-" + "first");
        childrenList2.add(parentList.get(1).getFname()+ "-" + "second");
        childrenList2.add(parentList.get(1).getFname() + "-" + "third");
        childrenList3.add(parentList.get(2).getFname() + "-" + "first");
        childrenList3.add(parentList.get(2).getFname() + "-" + "second");
        childrenList3.add(parentList.get(2).getFname()+ "-" + "third");
        dataset.put(parentList.get(0).getFname(), childrenList1);
        dataset.put(parentList.get(1).getFname(), childrenList2);
        dataset.put(parentList.get(2).getFname(), childrenList3);
    }
}
